home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / pmake / customs / customs.h < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-15  |  8.2 KB  |  243 lines

  1. /*-
  2.  * customs.h --
  3.  *    Header for the customs agent.
  4.  *
  5.  * Copyright (c) 1988, 1989 by the Regents of the University of California
  6.  * Copyright (c) 1988, 1989 by Adam de Boor
  7.  * Copyright (c) 1989 by Berkeley Softworks
  8.  *
  9.  * Permission to use, copy, modify, and distribute this
  10.  * software and its documentation for any non-commercial purpose
  11.  * and without fee is hereby granted, provided that the above copyright
  12.  * notice appears in all copies.  The University of California,
  13.  * Berkeley Softworks and Adam de Boor make no representations about
  14.  * the suitability of this software for any purpose.  It is provided
  15.  * "as is" without express or implied warranty.
  16.  *
  17.  *    "$Id: customs.h,v 1.19 89/11/14 13:46:26 adam Exp $ SPRITE (Berkeley)"
  18.  */
  19. #ifndef _CUSTOMS_H_
  20. #define _CUSTOMS_H_
  21.  
  22. /*
  23.  * First comes stuff needed by both the client and the server...
  24.  */
  25. #include    <sys/types.h>
  26. #include    <sys/socket.h>
  27. #include    <sys/param.h>
  28. #include    <netinet/in.h>
  29.  
  30. #ifndef INADDR_LOOPBACK
  31. #define    INADDR_LOOPBACK        (u_long)0x7f000001    /* in host order */
  32. #endif /* INADDR_LOOPBACK */
  33.  
  34. #include    "rpc.h"
  35.  
  36. #define MACHINE_NAME_SIZE       64              /* Longest machine name */
  37. #define MAX_DATA_SIZE            2048            /* Largest RPC arg packet */
  38. #define MAX_INFO_SIZE            MAX_DATA_SIZE    /* Most data returned by
  39.                          * CUSTOMS_INFO call */
  40. #define MAX_NUM_GROUPS        16              /* Most groups a caller
  41.                          * can be in. Don't use
  42.                          * NGROUP as that varies from
  43.                          * OS to OS. */
  44.  
  45. typedef enum {
  46. /* CLIENT FUNCTIONS */
  47.     CUSTOMS_PING,     /* See if server is up */
  48.     CUSTOMS_HOST,     /* Get address of host to use */
  49.     CUSTOMS_AVAILINTV,    /* Set interval for availability check */
  50.     CUSTOMS_SETAVAIL,    /* Set availability criteria */
  51.     CUSTOMS_INFO,     /* Find who's registered */
  52.     CUSTOMS_MASTER,    /* Find address of MCA */
  53.     CUSTOMS_LOG,      /* Log information of rpc socket */
  54. /* AGENT-INTERNAL FUNCTIONS */
  55.     CUSTOMS_AVAIL,    /* Tell master if machine available */
  56.     CUSTOMS_HOSTINT,    /* Agent-internal HOST call */
  57.     CUSTOMS_REG,      /* Register local machine with master */
  58.     CUSTOMS_ALLOC,    /* Local machine allocated by master */
  59.     CUSTOMS_CONFLICT,    /* More than one master exists */
  60. /* ELECTION BROADCAST FUNCTIONS */
  61.     CUSTOMS_CAMPAIGN,    /* Attempt to become master */
  62.     CUSTOMS_NEWMASTER,    /* Declare oneself master */
  63. /* IMPORT/TCP FUNCTIONS */
  64.     CUSTOMS_IMPORT,    /* Import a job */
  65.     CUSTOMS_KILL,     /* Kill a running job with a signal */
  66.     CUSTOMS_EXIT,     /* RETURN CALL: status and id # of exited process */
  67. /* DEBUG FUNCTIONS */
  68.     CUSTOMS_ABORT,    /* Exit */
  69.     CUSTOMS_RESTART,    /* Reexecute with same arguments */
  70.     CUSTOMS_DEBUG,    /* Turn on debugging. */
  71.     CUSTOMS_ELECT,      /* Start off a new election */
  72. } Customs_Proc;
  73.  
  74. /*
  75.  * Parameter to CUSTOMS_DEBUG
  76.  */
  77. #define DEBUG_RPC     1       /* Debug rpc system */
  78. #define DEBUG_CUSTOMS    2       /* Debug customs itself */
  79.  
  80. /*
  81.  * ExportPermits are what the servers use to authenticate exportation of
  82.  * jobs. They are returned to the client from a Customs_Host().
  83.  * CUSTOMS_FAIL may be used to see if the request succeeded. If it did not,
  84.  * CUSTOMS_FAIL(&permit.addr) will be True.
  85.  */
  86. #define CUSTOMS_FAIL(inaddrPtr)    ((inaddrPtr)->s_addr == INADDR_ANY)
  87.  
  88. typedef struct {
  89.     struct in_addr    addr;            /* Address of host */
  90.     u_long              id;          /* Authentication ID to give it */
  91. } ExportPermit;
  92.  
  93.  
  94. /*
  95.  * Host_Data is what is passed to the Customs_Host() function. It contains the
  96.  * UID under which the job will be exported (which must remain constant) and
  97.  * a word of flags indicating criteria to use to determine which host to use.
  98.  */
  99. typedef struct {
  100.     u_short             uid;
  101.     u_short        flags;
  102. } Host_Data;
  103. #define EXPORT_ANY    0x0001        /* Export to any sort of machine */
  104. #define EXPORT_SAME    0x0002        /* Export only to same sort of machine */
  105. #define EXPORT_USELOCAL    0x0004        /* Use local host if available */
  106. #define EXPORT_68020    0x0008        /* Go only to a 68020 (TEMPORARY) */
  107.  
  108. /*
  109.  * Avail_Data is what is passed to and returned from the Customs_SetAvail()
  110.  * function. changeMask contains a bitwise-OR of AVAIL_IDLE, AVAIL_SWAP,
  111.  * AVAIL_LOAD and AVAIL_IMPORTS, indicating what fields of the Avail_Data
  112.  * structure are valid. On return, changeMask indicates what fields in the
  113.  * request were invalid. If changeMask is 0, everything was accepted.
  114.  * The returned structure contains the current (after the change, if nothing
  115.  * was wrong) criteria.
  116.  * Load averages are sent as a fixed-point number. The location of the
  117.  * decimal point is given by LOADSHIFT. Divide by LOADSCALE to get the
  118.  * appropriate floating-point number.
  119.  */
  120. typedef struct {
  121.     long          changeMask;        /* Parameters to change */
  122.     long          idleTime;         /* Idle time (in seconds) */
  123.     long          swapPct;          /* Percentage of free swap space */
  124.     long          loadAvg;          /* Maximum load average */
  125.     long          imports;          /* Greatest number of imported processes */
  126. } Avail_Data;
  127.  
  128. #define AVAIL_IDLE        1
  129. #define MAX_IDLE          (60*60)
  130.  
  131. #define AVAIL_SWAP        2
  132. #define MAX_SWAP          40
  133.  
  134. #define LOADSHIFT           8
  135. #define LOADSCALE           (1<<LOADSHIFT)
  136. #define AVAIL_LOAD        4
  137. #define MIN_LOAD          ((int)(0.25*LOADSCALE))
  138.  
  139. #define AVAIL_IMPORTS        8
  140. #define MIN_IMPORTS        1
  141.  
  142. /*
  143.  * The next few constants are return values, some of them, and are not to
  144.  * be passed to the agent.
  145.  */
  146. #define AVAIL_DOWN        0x80000000    /* Machine is down -- this is *not* a
  147.                      * parameter */
  148. #define AVAIL_EVERYTHING    (~0)
  149.  
  150. /*
  151.  * Strings follow the WayBill in the CUSTOMS_IMPORT call arguments as
  152.  * follows:
  153.  *    current-working-directory
  154.  *    file                      # command to execute
  155.  *    number-o'-arguments         # on a 32-bit boundary
  156.  *    argument strings
  157.  *    number-o'-envariables        # on a 32-bit boundary
  158.  *    environment strings
  159.  *
  160.  * The function Customs_MakeWayBill will create an appropriate buffer...
  161.  */
  162. typedef struct {
  163.     u_long  id;                  /* Identifier returned by the MCA */
  164.     u_short port;             /* UDP Port for callback when process exits */
  165.     short   ruid;              /* The current real user id */
  166.     short   euid;             /* The current effective user id */
  167.     short   rgid;            /* The current real group id */
  168.     short   egid;             /* The current effective group id */
  169.     short   pad;                /* Explicit padding for all architectures */
  170.     long    umask;            /* File creation mask */
  171.     long    ngroups;            /* Number of groups */
  172.     long    groups[MAX_NUM_GROUPS];    /* Array of group ids */
  173. } WayBill;
  174.  
  175. /*
  176.  * Kill_Data is passed to the CUSTOMS_KILL procedure.
  177.  */
  178. typedef struct {
  179.     u_long  id;                    /* Job ID number (from ExportPermit) */
  180.     long    signo;            /* Signal number to deliver */
  181. } Kill_Data;
  182.  
  183.  
  184. /*
  185.  * Parameters to the CUSTOMS_EXIT call
  186.  */
  187. typedef struct {
  188.     u_long        id;            /* ID # of exported job */
  189.     long          status;       /* Exit status */
  190. } Exit_Data;
  191.  
  192. /*
  193.  * This is the time within which the daemon is "guaranteed" to respond.
  194.  */
  195. #define CUSTOMS_RETRY    2
  196. #define CUSTOMS_URETRY    500000
  197. #define CUSTOMS_NRETRY    2
  198.  
  199. #define Customs_Align(ptr, type)    (type) (((int)(ptr)+3)&~3)
  200.  
  201. /*
  202.  * Default ports if yellow pages f***s us over
  203.  */
  204. #define DEF_CUSTOMS_UDP_PORT    8231
  205. #define DEF_CUSTOMS_TCP_PORT    8231
  206.  
  207. /*
  208.  * Rpc front-ends
  209.  */
  210. Rpc_Stat    Customs_Host(),
  211.         Customs_Ping(),
  212.         Customs_UseLocal(),
  213.         Customs_SetAvail(),
  214.         Customs_AvailInterval(),
  215.         Customs_Master(),
  216.         Customs_Info();
  217. void        Customs_PError();
  218.  
  219. /*
  220.  * Return codes from Customs_RawExport, for anyone interested.
  221.  * If > -100, negation of result is Rpc_Stat code from call to local server.
  222.  * if <= -200, -(code + 200) is Rpc_Stat for call to remote server.
  223.  */
  224. #define CUSTOMS_NOEXPORT    -100        /* Couldn't export */
  225. #define CUSTOMS_NORETURN    -101        /* Couldn't create return socket */
  226. #define CUSTOMS_NONAME        -102        /* Couldn't fetch socket name */
  227. #define CUSTOMS_ERROR        -104        /* Remote export error -- message
  228.                      * already printed */
  229. #define CUSTOMS_NOIOSOCK    -105        /* Couldn't create tcp I/O socket */
  230.  
  231. /*
  232.  * Macro to deal with incompatible calling conventions between gcc and cc on
  233.  * a sparc (gcc passes the address in a register, since the structure is
  234.  * small enough, while cc still passes the address).
  235.  */
  236. #if defined(__GNUC__) && defined(sparc)
  237. #define InetNtoA(addr)    inet_ntoa(&(addr))
  238. #else
  239. #define InetNtoA(addr)    inet_ntoa(addr)
  240. #endif
  241.  
  242. #endif _CUSTOMS_H_
  243.